<template>
	<!--滑动优惠券-->
	<div>
		<div @touchstart="setstoptouch(false)" class="activitiesSlidePic" v-if="dataList && dataList.length>0">
			<banner style="width:100%; height: 100%; position:relative;" :bounce="true">
				<ul>
					<li v-for="(item,index) in dataList" :key="index+'slide'">
						<img v-lazy="item.publicityPicture" :key="item.publicityPicture" @click='jumpEvent(item)' src="static/image/demo1.png" />
					</li>
				</ul>
				<div style="clear: both;"></div>
			</banner>
		</div>
		<div v-if="dataList.length==0 && env === 'edit'" style="height: 2.5rem;line-height: 2.5rem;">请配置数据</div>
	</div>
</template>

<script>
	import { mapMutations } from "vuex";
	import Banner from '../../components/BannerScroll';
	import handlePath from "../../utils/lxn/handlePath"
	import { NAVIGATE } from "../../config/postMessage-types";
	import {mapGetters} from "vuex";
	export default {
		props: {
			dataList: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {

			}
		},
		components: {
			Banner
		},
		methods: {
			...mapMutations('xxy', [
				"setstoptouch"
			]),
			jumpEvent(item) {
				if (!item.extendField) return;
				if (!this.isApp) {
					// var urldata = JSON.parse(item.extendField).url.path
					var urldata = handlePath(item)
					if(urldata) {
						this.$router.push({
							path : urldata
							// name: "MiddleWare",
							// params: {
							// 	pageName: urldata
							// }
						})
					}
				} else if (this.isApp){
					if(!urldata){return}
					var urldata = JSON.parse(item.extendField).url
					if(urldata.valueArray[0] == '商品详情页面' ) {
						this.gotornpage('Detail', urldata.path.split("=")[1])
					} else if(urldata.valueArray[0] == '分类页面'){
						this.gotornpage('GoodsClassify', urldata.path.split("=")[1])
					}else if(urldata.valueArray[0] == '其他页面') {
						if(urldata.path == 'IntegralBuy') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}else{
								this.gotornpage(urldata.path)
							}
						}else if(urldata.path == 'Coupons'){
							this.gotornpage('CouponsAcquire')
						} else if (urldata.path == 'buyGiftCard') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							} else{
								this.gotornpage('BuyGiftCard')
							}
						} else if(urldata.path == 'foodChecked'){
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}
							else{
								this.gotornpage('FoodCheck')
							}
						} else if(urldata.path == 'prize_card'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'integral'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'login'){
							this.gotornpage('Login')
						} else if(urldata.path == 'register'){
							this.gotornpage('Regrester')
						} else {
							this.$router.push({
								name: "MiddleWare",
								params: {
									pageName: urldata.path
								}
							})
						}
					}
				}
			},
			gotornpage(page, code) {
				let params = {}
				if(page=='Detail'){
					params = {
						screen: page,
						params:{
							goodsCode: code
						}
					}
				}else if(page=='GoodsClassify'){
					params = {
						screen: page,
						params:{
							classCode: code
						}
					}
				} else {
					params = {
						screen: page,
					}
				}
				let goBackIns = {
					type: NAVIGATE,
					params: params
				}
				window.postMessage(JSON.stringify(goBackIns));
			}

		},
		computed: {
			env() {
				return window.environment; // 获取是否是编辑状态
			},
			isApp() {
				return window.isApp;
			},
			...mapGetters('wxh', [
                'userInfo'
            ]),
            hasUserInfo() {
                return Object.keys(this.userInfo).length;
            },
		},
		mounted() {

		},
	}
</script>

<style>
	.activitiesSlidePic {
		padding: 0.5rem 0.2rem;
	}
	
	.activitiesSlidePic ul {
		float: left;
		display: flex;
		min-width: 100%;
		position: relative;
	}
	
	.activitiesSlidePic ul li {
		width: 5.9rem;
		height: 2.82rem;
		margin: 0rem 0.1rem;
	}
	
	.activitiesSlidePic ul li img {
		width: 100%;
		height: 100%;
	}
</style>